import pandas as pd
import numpy as np
import akshare as ak
import datetime
from tqdm import tqdm
from multiprocessing import Process, Pool 
import os 
#  ak.fund_etf_category_sina(symbol="LOF基金") 
#  fund_etf_hist_sina
# fund_etf_fund_info_em_df = ak.fund_etf_fund_info_em(fund="511280", start_date="20000101", end_date="20500101")
# print(fund_etf_fund_info_em_df)

class Get_price():
    def __init__(self, path=r'data/etf_data/daily_price'):
        self.end_date = str(datetime.date.today())
        self.path = path 
        if not os.path.exists(self.path):
            os.makedirs(self.path)
        self.index = 'date'
        
    def get_price(self, code_list):
        for i in tqdm(code_list):
            try:
                result = ak.fund_etf_hist_sina(symbol=i)
                result[self.index] = result[self.index]
                result.index = pd.to_datetime(result[self.index])
                result.drop(columns=self.index, inplace=True)
                # result.replace('',np.nan, inplace=True)
                result = result.astype(float)  
                result.to_pickle(f'{self.path}/{i}.pkl.gzip')
            except:
                print('error:', i)
                continue
